<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>沙立方</title>
	<meta name="description" content="">
	<meta name="keywords" content="">
	<meta name="renderer" content="webkit">
	<!-- 设置缩放 -->
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
	<!-- 可隐藏地址栏，仅针对IOS的Safari（注：IOS7.0版本以后，safari上已看不到效果） -->
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<!-- 仅针对IOS的Safari顶端状态条的样式（可选default/black/black-translucent ） -->
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
	<meta name="format-detection" content="telephone=no, email=no" />
	<!-- 启用360浏览器的极速模式(webkit) -->
	<meta name="renderer" content="webkit">
	<!-- 避免IE使用兼容模式 -->
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
	<meta name="HandheldFriendly" content="true">
	<!-- 微软的老式浏览器 -->
	<meta name="MobileOptimized" content="320">
	<!-- uc强制竖屏 -->
	<meta name="screen-orientation" content="portrait">
	<!-- QQ强制竖屏 -->
	<meta name="x5-orientation" content="portrait">
	<!-- UC强制全屏 -->
	<meta name="full-screen" content="yes">
	<!-- QQ强制全屏 -->
	<meta name="x5-fullscreen" content="true">
	<!-- UC应用模式 -->
	<meta name="browsermode" content="application">
	<!-- QQ应用模式 -->
	<meta name="x5-page-mode" content="app">
	<!-- windows phone 点击无高光 -->
	<meta name="msapplication-tap-highlight" content="no">
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="icon" type="image/png" href="../assets/i/favicon.png">
	<link rel="stylesheet" href="../assets/city/jquery-weui.min.css" />
	<link rel="stylesheet" href="../assets/css/amazeui.min.css" />
	<link rel="stylesheet" href="../assets/css/app.css">
	<link rel="stylesheet" href="../assets/css/yttApp.css">
	
</head>

<body class="bg-FFFBF2 register">
	<header data-am-widget="header" class="am-header bg-white am-header-fixed borBottom bg-085492">
		<div class="am-header-left am-header-nav text-black padding-left05">
			<a href="javascript:history.go(-1)" class="text-black">
				<i class="am-align-left am-margin-0 am-icon-angle-left am-icon-md text-black co-fff"></i>
			</a>
		</div>
		<h1 class="am-header-title teblack">
			<a href="#title-link" class="co-fff">注册</a>
		</h1>
	</header>
	<div class="am-container">
	   <div class="registerForm">
	       <div class="inputDiv">
	           <div class="requrInputDiv">
		           <span class="titleInput">手机号</span>
		           <input type="tel" class="inputRegister bg-FFFBF2 public" id="phone" name="phone"  minlength="11" />
		           <img src="../img/phoneIcon.png" class="phoneIcon" />
	           </div>
	           <div class="requrIcon"><font style="color:red;">*</font></div>
	       </div>
	       <div class="font12 phone_validation unified" style="display:none">手机号码格式错误</div>
	       <div class="inputDiv">
	           <div class="requrInputDiv">
		           <span class="titleInput">验证码</span>
		           <input type="number" id="code_input" class="codeInput bg-FFFBF2 public"  />
		           <button class="codeBtn" id="code_btn">获取验证码</button>
		       </div>
	           <div class="requrIcon"><font style="color:red;">*</font></div>
	       </div>
	       <div class="font12 code_validation unified" style="display:none">验证码有误</div>
	       <div class="inputDiv">
	           <div class="requrInputDiv">
		           <span class="titleInput">上课校区</span>
		           <select id="schoolname" class="inputRegister bg-FFFBF2">

					</select>
		       </div>
	           <div class="requrIcon"><font style="color:red;">*</font></div>
	       </div>
	       <div class="inputDiv">
	           <div class="requrInputDiv">
		           <span class="titleInput">所在城市</span>
		           <input type="text" id="citys" name="citys" class="inputRegister bg-FFFBF2 public" readonly="readonly" onfocus="this.blur();" />
		       </div>
	           <div class="requrIcon"><font style="color:red;">*</font></div>
	       </div>
	       <div class="font12 city_validation unified" style="display:none">所在城市必填</div>
	       <div class="inputDiv">
	           <div class="requrInputDiv">
		           <span class="titleInput">详细地址</span>
		           <input type="text" id="citys_jd" class="inputRegister bg-FFFBF2 public"  />
		       </div>
	       </div>
	       <div class="font12 addr2_validation unified" style="display:none">详细地址需大于3个字</div>
	       <div class="promptDiv">（填写赠送10立方币）</div>
	   </div>
	   <div class="loginBtnDiv">
	       <span class="co-39" onclick="javascript:window.location.href='login.html'">已有账号，立即登录 ></span>
	   </div>
	   <div class="registerBtnDiv"><button class="reginBtn" id="register">注册</button></div>
	</div>
	
	<div class="am-modal am-modal-loading am-modal-no-btn radius4" tabindex="-1" id="my-modal-loading" data-am-modal="{closeViaDimmer: 0}">
		  <div class="am-modal-dialog" style="border-radius: 4px;">
		    	<div class="am-modal-hd">加载中...</div>
			    <div class="am-modal-bd">
			      <span class="am-icon-spinner am-icon-spin"></span>
			    </div>
		  </div>
	</div>
	<!-- 登录弹窗 -->
	<div class="am-modal am-modal-alert" tabindex="-1" id="operationModal" data-am-modal="{closeViaDimmer: 0}">
	  <div class="am-modal-dialog" style="border-radius: 4px;">
	    	<div class="am-modal-hd"></div>
		   	<div class="am-modal-bd operationModalBody"></div>
	   		<div class="am-modal-footer">
		      <span class="am-modal-btn" data-am-modal-confirm>去登录</span>
		      <span class="am-modal-btn" data-am-modal-cancel>取消</span>
		    </div>
  		</div>
	</div>
	<div class="am-modal am-modal-alert" tabindex="-1" id="alert1" data-am-modal="{closeViaDimmer: 0}">
		  <div class="am-modal-dialog" style="border-radius: 4px;">
		    	<div class="am-modal-hd"></div>
			   	<div class="am-modal-bd alert1"></div>
		   		<div class="am-modal-footer">
		      		<span class="am-modal-btn" data-am-modal-confirm>确定</span>
		    	</div>
	  		</div>
		</div>
		
	<script src="../assets/js/jquery.min.js"></script>
	<script src="../assets/js/jquery.cookie.js"></script>
	<script src="../assets/city/jquery-weui.min.js"></script>
	<script src="../assets/city/city-picker.min.js"></script>
	<script src="../assets/js/amazeui.min.js"></script>
	<script src="../assets/js/fastclick.min.js"></script>
	<script src="../js/comm.js"></script>
	<script src="../js/slf.js"></script>
	<script>
		$(function () {
			getschoolName();
			getIdentifyCode();
			register();
            $("#childuserBirthday").click(function(){
            	var t = $(window).scrollTop();
            	$('body,html').animate({'scrollTop':t+300},100)
            })
            $('.public').on('click',function(){
				$('.phone_validation').css('display','none');
				$('.code_validation').css('display','none');
				$('.city_validation').css('display','none');
				$('.addr2_validation').css('display','none');
			})
            //获取学校
			function getschoolName() {
				slf.ajax({
					url: "/register/getSchoolList",
					success: function (data) {
						if (data.obj.length > 0) {
							var school = data.obj;
							var html = "";
							for (var i = 0; i < school.length; i++) {
								html += "<option value=" + school[i].id + ">" + school[i].value + "</option>"
							}
							$("#schoolname").append(html);
						}
					}
				});
				getCity();
			}

			function getCity() {
				$("#citys").cityPicker({
					title: "选择省市区/县",
					onChange: function (picker, values, displayValues) {
						console.log(values, displayValues);
					}
				});
			}

			function getIdentifyCode() {
				$("#code_btn").click(sendIdentifyCode);
			}
			
			var counts = 0;
			function sendIdentifyCode() {
				counts++;
				console.log("1");
				regular = /^1[345789]\d{9}$/;
				var phone = $.trim($("#phone").val());
				if (!regular.test(phone)) {
					$('.phone_validation').css('display','block');
					counts =0;
				} else if(counts == 1){
					slf.ajax({
						url: "/sendIdentifyCode",
						param: {
							phone: phone,
							flag:0,
						},
						success: function (data) {
							if(data.res==1){
								values = "短信发送成功！";
								$('.alert1').text(values);
								$('#alert1').modal({
									closeViaDimmer: false,
								}); 
								$("#code_btn").unbind();
								$("#code_btn").removeClass("code_btn").addClass("code_btn2")
								var count = 1;
								var sum = 60;
								var i = setInterval(function () {
									if (count > 59) {
										$("#code_btn").text('获取验证码');
										$("#code_btn").removeClass("code_btn2").addClass("code_btn")
										$("#code_btn").bind('click', sendIdentifyCode);
										clearInterval(i);
									} else {
										$("#code_btn").text('剩余' + parseInt(sum - count) + '秒');
									}
									count++;
								}, 1000);
							}else if(data.res==0){
								$(".operationModalBody").html(data.resMsg);
								$('#operationModal').modal({
									closeViaDimmer: false,
									onConfirm: function(options) {
										window.location.href = "login.html"
							        },
								});
							}
						}
					
					});
					counts =0;
				}
			}
			//验证
			//手机号码
			$('#phone').on('input',function(){
				$('.phone_validation').css('display','none');
			})
			$('#phone').on('blur',function(){
				var phone = $.trim($("#phone").val());
				var regular = /^1[345789]\d{9}$/;
				if (!regular.test(phone)) {
					console.log("sdf");
					$('.phone_validation').css('display','block');
				}
			})
			//手机验证码
			$('#code_input').on('input',function(){
				$('.code_validation').css('display','none');
			})
			//注册
			function register() {
				$("#register").click(function (){
					var phone = $.trim($("#phone").val());
					var identifyCode = $.trim($("#code_input").val());
					var address = $.trim($("#citys").val());
					var schoolName = $.trim($("#schoolname").find("option:selected").text());
					var detailedAddress = $.trim($("#citys_jd").val());
					var schoolId = $.trim($("#schoolname").val());
					var recommendId = slf.getQueryStringByName('recommendId').replace(/\+/g, "2B2B%") || '';
                    var type = slf.getQueryStringByName('type').replace(/\+/g, "2B2B%") || '';
					var regular = /^1[345789]\d{9}$/;
					if (phone.length < 1) {
						$('.phone_validation').css('display','block');
					} else if (!regular.test(phone)) {
						$('.phone_validation').css('display','block');
					} else if (address.length < 1) {
						$('.city_validation').css('display','block');
					} else if (identifyCode.length < 1) {
						$('.code_validation').css('display','block');
					} else if(detailedAddress!=''&&detailedAddress.length<4){
						$('.addr2_validation').css('display','block');
					}else{
					    if(schoolName!=null&&schoolName!=''&&schoolId!=null&&schoolId!=''&&identifyCode!=null&&identifyCode!=''){
                            slf.ajax({
                                url: "/register/userRegister",
                                param: {
                                    phone : phone,
                                    schoolName : schoolName,
                                    schoolId : schoolId,
                                    identifyCode : identifyCode,
                                    address : address,
                                    detailedAddress : detailedAddress,
                                    recommendId : recommendId,
									type:type
                                },
                                success: function (data) {
                                    console.log(data)
                                    if (data.res == 1) {
                                        $('.alert1').html(data.resMsg);
                                        $('#alert1').modal({
                                        	closeViaDimmer: false,
                                        });
                                        setTimeout(function(){
                                        	window.location.href = "/slf/registerChild.html?schoolId="+schoolId+""
                                        },1000)
                                    }else{
                                        $('.alert1').html(data.resMsg);
                                        $('#alert1').modal();
                                    }
                                }
                            });
						}else{
					        alert("请完善资料")
						}
					}
				});
			}
		});
	</script>
</body>
</html>